﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TalentPools.Model;
using System.Data;
using System.Data.SqlClient;

namespace TalentPools.DAL
{
    public class IntentionService
    {
        public bool DeleteInten(int resumeId)
        {
            string sql = "delete from intention where resumeId=@resumeId";
            SqlParameter para = new SqlParameter("@resumeId", resumeId);
            return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) > 0;
        }
        #region 查询求职意向
        /// <summary>
        /// 根据简历ID查询求职意向
        /// </summary>
        /// <param name="resumeId"></param>
        /// <returns></returns>
        public List<intention> GetIntentionByResumeId(int resumeId)
        {
            string sql = "select top 1 * from intention where resumeId=@resumeId";
            SqlParameter para = new SqlParameter("@resumeId", resumeId);
            List<intention> list = new List<intention>();
            using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,para))
            {
                while (dr.Read())
                {
                    intention inten = new intention();
                    inten.id = Convert.ToInt32(dr["id"]);
                    inten.jobCategory = dr["jobCategory"].ToString();
                    inten.area = dr["area"].ToString();
                    inten.profession = dr["profession"].ToString();
                    inten.industry = dr["industry"].ToString();
                    inten.pay = dr["pay"].ToString();
                    inten.state = dr["state"].ToString();
                    inten.resumeId = Convert.ToInt32(dr["resumeId"]);
                    list.Add(inten);
                }
                return list;
            }
        }

        #endregion
    }
}
